package com.company.planner.entity;

import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.haulmont.cuba.core.entity.annotation.OnDeleteInverse;
import com.haulmont.cuba.core.global.DeletePolicy;

import javax.persistence.*;

@Table(name = "PLANNER_MAPPINGS")
@Entity(name = "planner_Mappings")
@NamePattern("%s|mappingName")
public class Mappings extends StandardEntity {
    private static final long serialVersionUID = 6907556581234254429L;

    @Column(name = "NAME")
    private String mappingName;

    @Column(name = "MAPPING_TYPE")
    private String mappingType;

    @Column(name = "LEVEL_")
    private Integer level;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "INDEXS_ID")
    private Indexs indexs;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MAPPING_ID")
    @OnDeleteInverse(DeletePolicy.CASCADE)
    private Mappings mapping;

    public NestedLevel getLevel() {
        return level == null ? null : NestedLevel.fromId(level);
    }

    public void setLevel(NestedLevel level) {
        this.level = level == null ? null : level.getId();
    }

    public Mappings getMapping() {
        return mapping;
    }

    public void setMapping(Mappings mapping) {
        this.mapping = mapping;
    }

    public Indexs getIndexs() {
        return indexs;
    }

    public void setIndexs(Indexs indexs) {
        this.indexs = indexs;
    }

    public String getMappingType() {
        return mappingType;
    }

    public void setMappingType(String mappingType) {
        this.mappingType = mappingType;
    }

    public String getMappingName() {
        return mappingName;
    }

    public void setMappingName(String mappingName) {
        this.mappingName = mappingName;
    }
}